package com.asset.web.purchase;

import com.asset.pojo.Brand;
import com.asset.service.BrandService;
import com.asset.util.PageResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 11725
 */
@RestController
@RequestMapping("/brand")
public class BrandController {

    @Resource
    private BrandService brandService;

    /**
     * 分页查询 | 查询全部信息
     * @param page          页码
     * @param rows          行数
     * @param selectAll     是否查询全部
     * @return              结果集
     */
    @GetMapping("/list")
    public ResponseEntity<PageResult<Brand>> selectByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "rows", defaultValue = "10") Integer rows,
            @RequestParam(value = "selectAll", required = false) Boolean selectAll) {
        return ResponseEntity.ok(brandService.selectByPage(page, rows, selectAll));
    }

    /**
     * 根据 id 查询品牌信息
     * @param id            品牌 id
     * @return              Brand 对象
     */
    @GetMapping("/{id}")
    public ResponseEntity<Brand> selectById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(brandService.selectById(id));
    }


    /**
     * 新增品牌信息
     * @param brand         Brand 对象
     * @return              void
     */
    @PostMapping
    public ResponseEntity<Void> insert(@RequestBody Brand brand) {
        brandService.insert(brand);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    @PutMapping
    public void update(@RequestBody Brand brand) {

    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable("id") Long id) {

    }
}
